<?php

declare(strict_types=1);

namespace Tool\Database\MockType;

use Tool\Database\AbstractColumn;

/**
 * 整数类型.
 */
class Integer extends AbstractColumn
{
    public function __construct(array &$column)
    {
        parent::__construct($column);

        if (!$this->isPrimaryKey()) {
            $this->extArgs[] = 1;
            $this->extArgs[] = 100;
        }
    }

    /**
     * {@inheritDoc}
     */
    protected function mock()
    {
        if ($this->isPrimaryKey()) {
            return $this->count;
        }

        if (2 === count($this->extArgs)) {
            return mt_rand(intval($this->extArgs[0]), intval($this->extArgs[1]));
        }

        return $this->defaultValue(0);
    }
}
